import { Request, Response, NextFunction } from "express";

export interface CustomResponse extends Response {
  cc(err: any, status?: number): Response
}

export const errorHandler = (req: Request, res: CustomResponse, next: NextFunction) => {
  res.cc = (err: any, status: number = 500) => {
    return res.status(status).send({
      status,
      message: err instanceof Error ? err.message : err,
    })
  }
  next()
}
